﻿using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;


public partial class Main_Ledger_EditLedger : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = "";
    string LID = "";
    string LedgerID = "";
    protected void Page_Load(object sender, EventArgs e)
    {       
            if (Request.QueryString["LID"] != null)
            {
                LID = Request.QueryString["LID"].ToString();
                //strsql = "Select OTHSALEPERSONCAP From IVR_SETTINGS";
                //DataTable DT = DU.getdata(strsql);
                //if (DT.Rows.Count > 0)
                //{
                //    lblOtherSalesPersonMain.Text = DT.Rows[0]["OTHSALEPERSONCAP"].ToString();
                //}
                //else
                //{
                //    lblOtherSalesPersonMain.Text = "Sale Person";
                //}
                
                
            if (!IsPostBack)
              {
                
                BindTaxType();
                //BindItemGroup();
                //BindTaxMainClass();
                //BindTaxSubClass();
                bindstate();
                nameBind();                
                DeliveryNameBind();
                BindSalePerson();
                BindPriceGroup();
                BindDDLServices();
                BindTaxGroupPurchase();
                BindTaxGroupSales();
                BindLedgerMain_Tax_Details();
                BindLedgerAddress();
                BindLedgerDeliveryAddress();
                BindContactPerson();
                BindTermCondition();
                BindOtherDetails();
                BindRegistrationDetails();
                
            }
        }
    }

    protected void BindTermCondition()
    {
        strsql = "select TRMID,TRMDESC from ACC_TERMSCONDITIONS Order By TRMDESC ASC";
        DataTable dt = DU.getdata(strsql);
        lstTermCondition.DataSource = dt;
        lstTermCondition.DataTextField = "TRMDESC";
        lstTermCondition.DataValueField = "TRMID";
        lstTermCondition.DataBind();
        lstTermCondition.Items.Insert(0, new ListItem("", "0"));

        string sql1 = "select TRMID from ACC_LEDTERMSCONDITIONS where lid="+LID;
        DataTable DT = DU.getdata(sql1);
        if (DT.Rows.Count>0)
        {
            lstTermCondition.SelectedValue = DT.Rows[0][0].ToString();
        }
        else
        {
            lstTermCondition.SelectedValue = "0";
        }
               
    }

    protected void BindItemGroup()
    {
        strsql = "select GID,GNAME from ACC_GRPMAST Order By GNAME";
        DataTable dt = DU.getdata(strsql);
        DDLGroupName.Items.Clear();
        DDLGroupName.DataSource = dt;
        DDLGroupName.DataTextField = "GNAME";
        DDLGroupName.DataValueField = "GID";
        DDLGroupName.DataBind();
        DDLGroupName.SelectedIndex = 0;
    }
    protected void BindLedger()
    {
        DataTable dt = DU.getdata("select LID,LNAME from ACC_LEDMAST where ALWSUB='True' Order by Lname");
        DDLGroupName.Items.Clear();
        DDLGroupName.DataSource = dt;
        DDLGroupName.DataTextField = "LNAME";
        DDLGroupName.DataValueField = "LID";
        DDLGroupName.DataBind();

    }
    protected void BindTaxType()
    {
        strsql = "select * from ACC_TAXTYPE";
        DataTable DT = DU.getdata(strsql);
        DDLTaxType.DataSource = DT;
        DDLTaxType.DataTextField = "TAXTYPE";
        DDLTaxType.DataValueField = "TAXTYPEID";
        DDLTaxType.DataBind();
        DDLTaxType.Items.Insert(0, new ListItem("", "0"));
    }
    protected void BindTaxMainClass()
    {
        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue)
                                };

        DataTable DT = DU.getdatausingprocedure("USP_ACC_GetTaxMainClassNames", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLMainClass.DataSource = DT;
            DDLMainClass.DataTextField = "MAINCLASSNAME";
            DDLMainClass.DataValueField = "MAINCLASSID";
            DDLMainClass.DataBind();
        }
        else
        {
            DDLMainClass.Items.Clear();
            DDLMainClass.Items.Insert(0, new ListItem("", "0"));
            DDLMainClass.Enabled = false;
           

        }

    }
    protected void BindTaxMainClass(string taxtype)
    {
        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",taxtype.ToString())
                                };

        DataTable DT = DU.getdatausingprocedure("USP_ACC_GetTaxMainClassNames", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLMainClass.Enabled = true;
            DDLMainClass.DataSource = DT;
            DDLMainClass.DataTextField = "MAINCLASSNAME";
            DDLMainClass.DataValueField = "MAINCLASSID";
            DDLMainClass.DataBind();
        }
        else
        {
            DDLMainClass.Items.Clear();
            DDLMainClass.Items.Insert(0, new ListItem("", "0"));            
            DDLMainClass.Enabled = false;

        }

    }
    protected void BindTaxSubClass()
    {

        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue),
                                    new SqlParameter("@MAINCLASSID",DDLMainClass.SelectedValue)
                                     
                                };

        DataTable DT = DU.getdatausingprocedure("USP_ACC_GetLedTaxSubClass", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLSubClass.Enabled = true;
            DDLSubClass.DataSource = DT;
            DDLSubClass.DataTextField = "SUBCLASSNAME";
            DDLSubClass.DataValueField = "SUBCLASSID";
            DDLSubClass.DataBind();

        }
        else
        {
            DDLSubClass.Items.Clear();
            DDLSubClass.Items.Insert(0, new ListItem("", "0"));
            DDLSubClass.Enabled = false;
        }
    }

    protected void BindTaxSubClass(string taxtypeid ,string Mainclassid)
    {

        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",taxtypeid.ToString()),
                                     new SqlParameter("@MAINCLASSID",Mainclassid.ToString())
                                };

        DataTable DT = DU.getdatausingprocedure("USP_ACC_GetLedTaxSubClass", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLSubClass.Enabled = true;
            DDLSubClass.DataSource = DT;
            DDLSubClass.DataTextField = "SUBCLASSNAME";
            DDLSubClass.DataValueField = "SUBCLASSID";
            DDLSubClass.DataBind();
        }
        else
        {
            DDLSubClass.Enabled = false;
        }
    }


    protected void bindstate()
    {
        strsql = "select StateId,StateName from MAS_State";
        DataTable DT = DU.getdata(strsql);
        ddlState.DataSource = DT;
        
        ddlState.DataTextField = "StateName";
        ddlState.DataValueField = "StateId";
        ddlState.DataBind();
        ddlState.Items.Insert(0, new ListItem("---Select State---", "0"));
        ddlState.SelectedValue = "0";
        DDLDileveryState.DataSource = DT;
        DDLDileveryState.DataTextField = "StateName";
        DDLDileveryState.DataValueField = "StateId";
        DDLDileveryState.DataBind();
        DDLDileveryState.Items.Insert(0, new ListItem("---Select State---", "0"));
        DDLDileveryState.SelectedValue = "0";
    }
    protected void nameBind()
    {

        ddlName.Items.Add(new ListItem("M/s", "0"));
        ddlName.Items.Add(new ListItem("Mr.", "1"));
        ddlName.Items.Add(new ListItem("Mrs.", "2"));
        ddlName.Items.Add(new ListItem("Ms.", "3"));
        ddlName.Items.Add(new ListItem(" ", " "));
       
    }
    protected void DeliveryNameBind()
    {

        DDLDileveryName.Items.Add(new ListItem("M/s", "0"));
        DDLDileveryName.Items.Add(new ListItem("Mr.", "1"));
        DDLDileveryName.Items.Add(new ListItem("Mrs.", "2"));
        DDLDileveryName.Items.Add(new ListItem("Ms.", "3"));
        DDLDileveryName.Items.Add(new ListItem(" ", " "));
      
    }
    protected void BindSalePerson()
    {
        strsql = "Select SPRID,SPRNAME from ACC_SALESPERSON";
        DataTable DTSale = DU.getdata(strsql);
        if (DTSale.Rows.Count > 0)
        {
            //grdSalePerson.DataSource = DTSale;
            //grdSalePerson.DataBind();
            //*************Bind Data to Dropdownlist********//
            ddlSalePerson.DataSource = DTSale;
            ddlSalePerson.DataTextField = "SPRNAME";
            ddlSalePerson.DataValueField = "SPRID";
            ddlSalePerson.DataBind();
            ddlSalePerson.Items.Insert(0, new ListItem("", "0"));
        }

    }
    protected void BindPriceGroup()
    {
        strsql = "Select SPGID,SPGNAME from ACC_SALESPRICEGROUP";
        DataTable DTPrice = DU.getdata(strsql);
        if (DTPrice.Rows.Count > 0)
        {
            //grdPriceGroup.DataSource = DTPrice;
            //grdPriceGroup.DataBind();
            //*************Bind Data to Dropdownlist********//
            ddlPriceGroup.DataSource = DTPrice;
            ddlPriceGroup.DataTextField = "SPGNAME";
            ddlPriceGroup.DataValueField = "SPGID";
            ddlPriceGroup.DataBind();
            ddlPriceGroup.Items.Insert(0, new ListItem("", "0"));

        }

    }

    protected void BindLedgerMain_Tax_Details()
    {
        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTMain = DU.getdatausingprocedure("USP_ACC_GetLedger", sparam);
        if (DTMain.Rows.Count > 0)
        {
            TxtName.Text = DTMain.Rows[0]["LNAME"].ToString();
            TxtAlterName.Text = DTMain.Rows[0]["LANAME"].ToString();
            if (DTMain.Rows[0]["ALWSUB"].ToString() == "True")
            {
                CHKAllow.Checked = true;
            }
            if (DTMain.Rows[0]["LID"].ToString() == DTMain.Rows[0]["PLID"].ToString())
            {
                //BindLedger(); //Commented by Vikram on 01-dec-10
                BindItemGroup();
                DDLGroupName.SelectedValue = DTMain.Rows[0]["PGID"].ToString();

            }
            else
            {
                ChkSubLedger.Checked = true;
                BindLedger();
                DDLGroupName.SelectedValue = DTMain.Rows[0]["PLID"].ToString();
            }
            TxtOpeningBal.Text = DTMain.Rows[0]["ACTOPENING"].ToString();

            strsql = "Select ACTIVE from ACC_LEDOTHERDETAILS Where LID='" + DTMain.Rows[0]["LID"].ToString() + "'";
            DataTable DT3 = DU.getdata(strsql);
            if (DT3.Rows.Count > 0)
            {
                if (DT3.Rows[0]["ACTIVE"].ToString() == "True")
                {
                    CHKAvtive.Checked = true;
                }
                else
                {
                    CHKAvtive.Checked = false;
                }
            }
            else
            {
                CHKAvtive.Checked = false;
            }

            if (DTMain.Rows[0]["COSTCENTREAPPLY"].ToString() == "True")
            {
                ChkCost.Checked = true;
            }
            else
            {
                ChkCost.Checked = false;
            }
            if (DTMain.Rows[0]["STAPPLY"].ToString() == "True")
            {
                ChkService.Checked = true;
            }
            else
            {
                ChkService.Checked = false;
            }
            if (DTMain.Rows[0]["TDSAPPLY"].ToString() == "True")
            {
                ChkTDS.Checked = true;
            }
            else
            {
                ChkTDS.Checked = false;
            }




            SqlParameter[] sparam1 ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
            DataTable DTTax = DU.getdatausingprocedure("USP_ACC_GetLedgerTaxDetails", sparam1);
            if (DTTax.Rows.Count > 0)
            {
                if(Convert.ToDouble( DTTax.Rows[0]["TAXTYPEID"].ToString())>0)
                {
                    
                    DDLTaxType.SelectedValue= DTTax.Rows[0]["TAXTYPEID"].ToString();
                    BindTaxMainClass(DTTax.Rows[0]["TAXTYPEID"].ToString());
                    BindTaxSubClass(DTTax.Rows[0]["TAXTYPEID"].ToString(), DTTax.Rows[0]["MAINCLASSID"].ToString());
                }
                if (Convert.ToDouble(DTTax.Rows[0]["MAINCLASSID"].ToString()) > 0)
                {
                    
                    BindTaxMainClass(DTTax.Rows[0]["TAXTYPEID"].ToString());
                    DDLMainClass.SelectedValue = DTTax.Rows[0]["MAINCLASSID"].ToString();
                }
                if (Convert.ToDouble(DTTax.Rows[0]["SUBCLASSID"].ToString()) > 0)
                {
                    BindTaxSubClass(DTTax.Rows[0]["TAXTYPEID"].ToString(),DTTax.Rows[0]["MAINCLASSID"].ToString());
                    DDLSubClass.SelectedValue = DTTax.Rows[0]["SUBCLASSID"].ToString();
                }
                
                
                
            }
            else
            {
                DDLTaxType.SelectedValue = "0";
                DDLMainClass.SelectedValue = "0";
                DDLSubClass.SelectedValue = "0";
            }
        }
    }

        protected void BindLedgerAddress()
        {
            SqlParameter[] sparam ={
                                       new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                                   };
            DataTable DTAddress = DU.getdatausingprocedure("USP_ACC_GetLedgerAddressDetails", sparam);
            if (DTAddress.Rows.Count > 0)
            {

                ddlName.SelectedItem.Text = DTAddress.Rows[0]["TITLE"].ToString();
                txtAddName.Text = DTAddress.Rows[0]["LNAME"].ToString();
                txtAddress1.Text = DTAddress.Rows[0]["ADDRESS1"].ToString();
                txtAddress2.Text = DTAddress.Rows[0]["ADDRESS2"].ToString();
                txtAddress3.Text = DTAddress.Rows[0]["ADDRESS3"].ToString();
                txtAddPlace.Text = DTAddress.Rows[0]["PLACE"].ToString();
                txtPin.Text = DTAddress.Rows[0]["PINCODE"].ToString();
                
                ddlCountry.SelectedItem.Text= DTAddress.Rows[0]["COUNTRY"].ToString();

                txtEmail.Text = DTAddress.Rows[0]["EMAIL"].ToString();
                txtWebsite.Text = DTAddress.Rows[0]["WEBSITE"].ToString();
                txtPhone.Text = DTAddress.Rows[0]["PHONE"].ToString();
                txtFax.Text = DTAddress.Rows[0]["FAX"].ToString();
                ddlState.SelectedValue =DTAddress.Rows[0]["STATEID"].ToString();
                
            }
        }

    protected void BindTaxGroupPurchase()
    {
        DataTable DTPurchase = DU.getdatausingprocedure("USP_ACC_GetPurchaseMainClass");
        ddlPurchase.DataSource = DTPurchase;
        ddlPurchase.DataTextField = "MAINCLASSNAME";
        ddlPurchase.DataValueField = "MAINCLASSID";
        ddlPurchase.DataBind();
        ddlPurchase.Items.Insert(0, new ListItem("", "0"));
    }
    protected void BindTaxGroupSales()
    {
        DataTable DTSales = DU.getdatausingprocedure("USP_ACC_GetSalesMainClass");
        ddlSales.DataSource = DTSales;
        ddlSales.DataTextField = "MAINCLASSNAME";
        ddlSales.DataValueField = "MAINCLASSID";
        ddlSales.DataBind();
        ddlSales.Items.Insert(0, new ListItem("", "0"));
        
    }

        protected void BindLedgerDeliveryAddress()
        {
            SqlParameter[] sparam ={
                                       new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                                   };
            DataTable DTDelAddress = DU.getdatausingprocedure("USP_ACC_GetLedgerDeliveryAddressDetails", sparam);
            if (DTDelAddress.Rows.Count > 0)
            {

                DDLDileveryName.SelectedItem.Text = DTDelAddress.Rows[0]["TITLE"].ToString();
                txtDileveryName.Text = DTDelAddress.Rows[0]["CONTACTNAME"].ToString();
                txtDileveryAddress1.Text = DTDelAddress.Rows[0]["ADD1"].ToString();
                txtDileveryAddress2.Text = DTDelAddress.Rows[0]["ADD2"].ToString();
                txtDileveryAddress3.Text = DTDelAddress.Rows[0]["ADD3"].ToString();
                txtDileveryAddress4.Text = DTDelAddress.Rows[0]["ADD4"].ToString();
                txtDileveryPincode.Text = DTDelAddress.Rows[0]["PINCODE"].ToString();
                DDLDileveryCountry.SelectedItem.Text = DTDelAddress.Rows[0]["COUNTRY"].ToString();
               
                txtVat.Text = DTDelAddress.Rows[0]["LSTNUM"].ToString();
                txtDeliveryInterState.Text = DTDelAddress.Rows[0]["CSTNUM"].ToString();
                txtDeliveryCENVAT.Text = DTDelAddress.Rows[0]["CEPANUM"].ToString();
                txtDeliveryVatDate.Text = DTDelAddress.Rows[0]["LSTDATE"].ToString().Replace("01/01/1900", "");
                txtDeliveryInterStateDate.Text = DTDelAddress.Rows[0]["CSTDATE"].ToString().Replace("01/01/1900", "");
                txtDeliveryCENVATDate.Text = DTDelAddress.Rows[0]["CEPADATE"].ToString().Replace("01/01/1900", "");
               
                strsql = "Select STATENAME From MAS_State Where STATEID='" + DTDelAddress.Rows[0]["STATEID"].ToString() + "'";
                DataTable DTState = DU.getdata(strsql);
                if (DTState.Rows.Count > 0)
                {
                    DDLDileveryState.SelectedItem.Text = DTState.Rows[0]["STATENAME"].ToString();
                }
            }
        }


        protected void BindContactPerson()
        {
            SqlParameter[] sparam ={
                                       new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                                   };
            DataTable DTContact = DU.getdatausingprocedure("USP_ACC_GetLedgerContactDetails", sparam);
            if (DTContact.Rows.Count > 0)
            {
                txtContactPerson.Text = DTContact.Rows[0]["PERSON"].ToString();
                txtContactPosition.Text = DTContact.Rows[0]["POSITION"].ToString();
               
                txtContactPhone.Text = DTContact.Rows[0]["PHONENUM"].ToString();
                txtContactMobile.Text = DTContact.Rows[0]["MOBILENUM"].ToString();
                txtContactFax.Text = DTContact.Rows[0]["FAXNUM"].ToString();
                txtContactEmail.Text = DTContact.Rows[0]["EMAIL"].ToString();
                txtContactRemarks.Text = DTContact.Rows[0]["REMARKS"].ToString();
            }
        }

     protected void BindRegistrationDetails()
        {

            SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
            DataTable DTReg = DU.getdatausingprocedure("USP_ACC_GetRegistrationDetails", sparam);
            if (DTReg.Rows.Count > 0)
            {
                txtRegPAN.Text = DTReg.Rows[0]["PAN"].ToString();
                txtRegPANDate.Text = DTReg.Rows[0]["PANDATE"].ToString().Replace("01/01/1900", "");
                txtRegTaxDeduction.Text = DTReg.Rows[0]["TDSNO"].ToString();
                txtRegTaxDeductionDate.Text = DTReg.Rows[0]["TDSDATE"].ToString().Replace("01/01/1900", "");
                txtRegVAT.Text = DTReg.Rows[0]["VATTIN"].ToString();
                txtRegVATDate.Text = DTReg.Rows[0]["VATTINDATE"].ToString().Replace("01/01/1900", "");
                txtRegInterState.Text = DTReg.Rows[0]["CSTNO"].ToString();
                txtRegInterStateDate.Text = DTReg.Rows[0]["CSTDATE"].ToString().Replace("01/01/1900", "");
                txtRegServicetax.Text = DTReg.Rows[0]["SERTNO"].ToString();
                txtRegCVNNET.Text = DTReg.Rows[0]["CEPAN"].ToString();
                txtRegLuxury.Text = DTReg.Rows[0]["LTNO"].ToString();
                txtRegPanRef.Text = DTReg.Rows[0]["PANREF"].ToString();
                txtRegServiceTaxDate.Text = DTReg.Rows[0]["SERTNDATE"].ToString().Replace("01/01/1900", "");
                txtRegLuxuryDate.Text = DTReg.Rows[0]["LTNDATE"].ToString().Replace("01/01/1900", "");
                txtRegCVNNETDate.Text = DTReg.Rows[0]["CEPANDATE"].ToString().Replace("01/01/1900", "");
            }
        }


     protected void BindOtherDetails()
      {
  
        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTOther = DU.getdatausingprocedure("USP_ACC_GetLedgerOtherDetails", sparam);
        if (DTOther.Rows.Count > 0)
        {
            txtCreditPeriod.Text = DTOther.Rows[0]["CREDITPERIOD"].ToString();
            txtCreditLimit.Text = DTOther.Rows[0]["CREDITLIMIT"].ToString();

            ddlSalePerson.SelectedValue = DTOther.Rows[0]["SPRID"].ToString();
            ddlPriceGroup.SelectedValue = DTOther.Rows[0]["SPGID"].ToString();
            ddlPurchase.SelectedValue = DTOther.Rows[0]["PURTAXMAINCLASSID"].ToString();
            ddlSales.SelectedValue = DTOther.Rows[0]["SALETAXMAINCLASSID"].ToString();

            if(DTOther.Rows[0]["TCS"].ToString()=="True")
            {
                chkApplyTCS.Enabled = true;
                chkApplyTCS.Checked = true;
            }
            else
            {
                chkApplyTCS.Enabled = false;
                chkApplyTCS.Checked = false;
            }
         
        }
    }

     protected void ChkSubLedger_CheckedChanged(object sender, EventArgs e)
     {
         if (ChkSubLedger.Checked == true)
         {
             BindLedger();
             CHKAllow.Checked = false;
             TxtOpeningBal.Enabled = true;
             DDLServices.Enabled = true;
         }
         else if (ChkSubLedger.Checked == false)
         {
             BindItemGroup();

         }
     }
     protected void CHKAllow_CheckedChanged(object sender, EventArgs e)
     {
         if (CHKAllow.Checked == true)
         {
             //BindItemGroup();
             ChkSubLedger.Checked = false;
             TxtOpeningBal.Text = "0.00";
             TxtClosing.Text = "";
             TxtOpeningBal.Enabled = false;
             DDLServices.Enabled = false;
         }
         else if (CHKAllow.Checked == false)
         {
             TxtOpeningBal.Enabled = true;
             DDLServices.Enabled = true;
         }
     }

     protected void BindDDLServices()
     {
         DDLServices.Items.Add(new ListItem("Debit", "0"));
         DDLServices.Items.Add(new ListItem("Credit", "1"));
         DDLServices.SelectedValue = "0";
     }
    
     protected void BtnClose_Click(object sender, EventArgs e)
     {
         Response.Redirect("ViewLedger.aspx");
     }

     protected void BtnUpdate_Click(object sender, EventArgs e)
     {


         if (ValidateLedger1() && ValidateLedger())
         {

             if (ChkSubLedger.Checked == true)
             {
                 //lblMsg.Text = "Update with ledger";
                 UpdateWithLedger();
             }
             else
             {
                 //lblMsg.Text = "Update with group";
                 UpdateWithGroup();
             }

             UpdateTaxDetails();
             UpdateAddressDetails();
             UpdateDeliveryDetails();
             UpdateRegistrationDetails();
             UpdatetContactDetails();
             UpdateOthersDetails();
             UpdateTermConditions();
             lblMsg.Attributes.Remove("class");
             lblMsg.Attributes.Add("class", "true");
             lblMsg.Text = "Ledger Updated Successfully";
             Response.Redirect("ViewLedger.aspx");
         }
     }

     protected bool ValidateLedger1()
     {
         strsql = "Select * from ACC_LEDMAST Where LANAME='" + TxtAlterName.Text + "'  AND LANAME<>'' and lid!=" + LID;
         //lblMsg.Text = strsql;
         DataTable DTAName = DU.getdata(strsql);
         if (DTAName.Rows.Count > 0)
         {
             lblMsg.Attributes.Remove("class");
             lblMsg.Attributes.Add("class", "false");
             lblMsg.Text = "Duplicate Alternate Ledger Name";
             TxtAlterName.Focus();
             return false;
         }
         else
         {
             return true;
         }
     }

     protected bool ValidateLedger()
     {
         strsql = "Select * from ACC_LEDMAST Where LNAME='" + TxtName.Text + "' and lid!=" + LID;
         //lblMsg.Text = strsql;
         DataTable DTName = DU.getdata(strsql);
         if (DTName.Rows.Count > 0)
         {
             lblMsg.Attributes.Remove("class");
             lblMsg.Attributes.Add("class", "false");
             lblMsg.Text = "Duplicate Ledger Name";
             TxtName.Focus();
             return false;
         }
         else
         {
             return true;
         }
     }

     protected void UpdateTaxDetails()
     {
         if (Convert.ToInt32(DDLTaxType.SelectedValue) > 0)
         {
             try
             {

                 string sql1 = "select * from ACC_LEDTAXDETAILS where lid=" + LID;
                 DataTable DT = DU.getdata(sql1);
                 if (DT.Rows.Count > 0)
                 {
                     
                     SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue),
                                            new SqlParameter("@MAINCLASSID",DDLMainClass.SelectedValue),
                                            new SqlParameter("@SUBCLASSID",DDLSubClass.SelectedValue),
                                            new SqlParameter("EName",Session["username"].ToString())
                                        };
                     DU.executeprocedure("usp_update_ACC_LedgerTaxDetails", sparam);

                 }

                 else
                 {
                    
                     SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue),
                                            new SqlParameter("@MAINCLASSID",DDLMainClass.SelectedValue),
                                            new SqlParameter("@SUBCLASSID",DDLSubClass.SelectedValue)
                                           
                                        };
                     DU.executeprocedure("USP_ACC_SaveLedgerTaxDetails", sparam);

                 }
             }


             catch (Exception ex)
             {
                 lblMsg.Text = ex.Message;
             }
         }
     }


        protected void UpdateWithGroup()
            {
            try
            {
                SqlParameter[] param = {
                                       new SqlParameter("@LID",LID),
                                      new SqlParameter("@PGID",DDLGroupName.SelectedValue),
                                      new SqlParameter("@LNAME",TxtName.Text.Trim()),
                                      new SqlParameter("@LANAME",TxtAlterName.Text.Trim()),
                                      new SqlParameter("@ACTOPENING", TxtOpeningBal.Text.Trim()),
                                      new SqlParameter("@BILLWISE",CHKBillWise.Checked),
                                      new SqlParameter("@ALWSUB",CHKAllow.Checked),                                  
                                      new SqlParameter("@TAXAPPLY",ChkTaxType.Checked),
                                      new SqlParameter("@COSTCENTREAPPLY",ChkCost.Checked),
                                      new SqlParameter("@TDSAPPLY",ChkTDS.Checked),
                                      new SqlParameter("@STAPPLY",ChkService.Checked),                                 
                                      new SqlParameter("EName",Session["username"].ToString())

                                  };
                DU.executeprocedure("usp_update_ACC_LEDMAST", param);
                //strsql = "Select Ident_Current('ACC_LEDMAST')as Lid";
                //DataTable DT = DU.getdata(strsql);
                //if (DT.Rows.Count>0)
                //{
                //    LedgerID = DT.Rows[0]["LID"].ToString();
                //    strsql = "Update ACC_LEDMAST set PLID='" + LedgerID.ToString() + "' where LID='" + LedgerID.ToString() + "'";
                //    int result = DU.executesql(strsql);
                //}    
               
            }
            catch (Exception ex)
            {
                lblMsg.Attributes.Remove("class");
                lblMsg.Attributes.Add("class", "false");
                lblMsg.Text = ex.Message;
            }                
        }

        protected void UpdateWithLedger()
        {
            try
            {
                strsql = "Select PGID from ACC_LEDMAST where LID='" + Request.QueryString["LID"].ToString() + "'";
                DataTable DT = DU.getdata(strsql);
                if (DT.Rows.Count > 0)
                {
                    SqlParameter[] param = {
                                                new SqlParameter("@LID",LID),
                                      new SqlParameter("@PGID",DT.Rows[0]["PGID"].ToString()),
                                      new SqlParameter("@LNAME",TxtName.Text.Trim()),
                                      new SqlParameter("@LANAME",TxtAlterName.Text.Trim()),
                                      new SqlParameter("@ACTOPENING", TxtOpeningBal.Text.Trim()),
                                      new SqlParameter("@BILLWISE",CHKBillWise.Checked),
                                      new SqlParameter("@ALWSUB",CHKAllow.Checked),                                  
                                      new SqlParameter("@TAXAPPLY",ChkTaxType.Checked),
                                      new SqlParameter("@COSTCENTREAPPLY",ChkCost.Checked),
                                      new SqlParameter("@TDSAPPLY",ChkTDS.Checked),
                                      new SqlParameter("@STAPPLY",ChkService.Checked),                                 
                                      new SqlParameter("EName",Session["username"].ToString())

                                  };
                    DU.executeprocedure("usp_update_ACC_LEDMAST", param);
                }
              //strsql = "Select Ident_Current('ACC_LEDMAST') as LID";
              // DataTable DT1 = DU.getdata(strsql);
              // if (DT1.Rows.Count > 0)
              // {
              //    LedgerID = DT1.Rows[0]["LID"].ToString();
              //    strsql = "Update ACC_LEDMAST set PLID='" + DDLGroupName.SelectedValue + "' where LID='" + Request.QueryString["LID"].ToString() + "'";
              //    int result = DU.executesql(strsql);
              //  }
               strsql = "Update ACC_LEDMAST set PLID='" + DDLGroupName.SelectedValue + "' where LID='" + Request.QueryString["LID"].ToString() + "'";
               int result = DU.executesql(strsql);
            }
            catch (Exception ex)
            {
                lblMsg.Attributes.Remove("class");
                lblMsg.Attributes.Add("class", "false");
                lblMsg.Text = ex.Message;
            }
        }

        protected void UpdateAddressDetails()
        {
            try
            {

                string sql1 = "select * from ACC_LEDADDRESS where lid=" + LID;
                DataTable DT = DU.getdata(sql1);
                if (DT.Rows.Count > 0)
                {
                    
                    SqlParameter[] sparam1 = 
                            { 
                                new SqlParameter("@LID",LID),
                                new SqlParameter("@TITLE",ddlName.SelectedItem.Text.Trim()),
                                new SqlParameter("@LNAME",txtAddName.Text.Trim()),
                                new SqlParameter("@ADDRESS1",txtAddress1.Text.Trim()),
                                new SqlParameter("@ADDRESS2",txtAddress2.Text.Trim()),
                                new SqlParameter("@ADDRESS3",txtAddress3.Text.Trim()),
                                new SqlParameter("@PLACE",txtAddPlace.Text.Trim()),
                                new SqlParameter("@PINCODE",txtPin.Text.Trim()),
                                new SqlParameter("@STATEID",ddlState.SelectedValue),
                                new SqlParameter("@COUNTRY",ddlCountry.SelectedItem.Text),
                                new SqlParameter("@WEBSITE",txtWebsite.Text.Trim()),
                                new SqlParameter("@EMAIL",txtEmail.Text.Trim()),
                                new SqlParameter("@PHONE",txtPhone.Text.Trim()),
                                new SqlParameter("@FAX",txtFax.Text.Trim()),
                                new SqlParameter("@EName",Session["username"].ToString()),
                            };

                      DU.executeprocedure("usp_update_ACC_LedgerAddressDetails", sparam1);

                }
                else
                {
                    SqlParameter[] sparam = 
                            { 
                                new SqlParameter("@LID",LID),
                                new SqlParameter("@TITLE",ddlName.SelectedItem.Text.Trim()),
                                new SqlParameter("@LNAME",txtAddName.Text.Trim()),
                                new SqlParameter("@ADDRESS1",txtAddress1.Text.Trim()),
                                new SqlParameter("@ADDRESS2",txtAddress2.Text.Trim()),
                                new SqlParameter("@ADDRESS3",txtAddress3.Text.Trim()),
                                new SqlParameter("@PLACE",txtAddPlace.Text.Trim()),
                                new SqlParameter("@PINCODE",txtPin.Text.Trim()),
                                new SqlParameter("@STATEID",ddlState.SelectedValue),
                                new SqlParameter("@COUNTRY",ddlCountry.SelectedItem.Text),
                                new SqlParameter("@WEBSITE",txtWebsite.Text.Trim()),
                                new SqlParameter("@EMAIL",txtEmail.Text.Trim()),
                                new SqlParameter("@PHONE",txtPhone.Text.Trim()),
                                new SqlParameter("@FAX",txtFax.Text.Trim()),
                                new SqlParameter("@CNAME",Session["username"].ToString())
                             
                            };
                    DU.executeprocedure("USP_ACC_SaveLedgerAddressDetails", sparam);
                }
            }
            catch (Exception ex)
            {
                lblMsg.Attributes.Remove("class");
                lblMsg.Attributes.Add("class", "false");
                lblMsg.Text = ex.Message;
            }
        }
        protected void UpdatetContactDetails()
        {
           try
            {

                string sql1 = "select * from ACC_LEDCONTACTDETAILS where lid=" + LID;
                DataTable DT = DU.getdata(sql1);
                if (DT.Rows.Count > 0)
                {
                    SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@PERSON",txtContactPerson.Text.Trim()),
                                            new SqlParameter("@POSITION",txtContactPosition.Text.Trim()),
                                            new SqlParameter("@PHONENUM",txtContactPhone.Text.Trim()),
                                            new SqlParameter("@MOBILENUM",txtContactMobile.Text.Trim()),
                                            new SqlParameter("@EMAIL",txtContactEmail.Text.Trim()),
                                            new SqlParameter("@FAXNUM",txtContactFax.Text.Trim()),
                                            new SqlParameter("@REMARKS",txtContactRemarks.Text.Trim()),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                            
                                        };
                    DU.executeprocedure("usp_update_ACC_LedgerContactDetails", sparam);
                   
                }
            else
            {
               // lblMsg.Text= "update";
                SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@PERSON",txtContactPerson.Text.Trim()),
                                            new SqlParameter("@POSITION",txtContactPosition.Text.Trim()),
                                            new SqlParameter("@PHONENUM",txtContactPhone.Text.Trim()),
                                            new SqlParameter("@MOBILENUM",txtContactMobile.Text.Trim()),
                                            new SqlParameter("@EMAIL",txtContactEmail.Text.Trim()),
                                            new SqlParameter("@FAXNUM",txtContactFax.Text.Trim()),
                                            new SqlParameter("@REMARKS",txtContactRemarks.Text.Trim()),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                            
                                        };

                DU.executeprocedure("USP_ACC_SaveLedgerContactDetails", sparam);

            }
           }
                catch (Exception ex)
                {
                    lblMsg.Attributes.Remove("class");
                    lblMsg.Attributes.Add("class", "false");
                    lblMsg.Text = ex.Message;
                }
            }

        protected void UpdateDeliveryDetails()
        {

            try
            {

                string sql1 = "select * from ACC_LEDDELIVERYADDDETAILS where lid=" + LID;
                DataTable DT = DU.getdata(sql1);
                if (DT.Rows.Count > 0)
                {
                    string LstDate = "";
                    string CSTDate = "";
                    string CepDate = "";

                  

                    if (txtDeliveryVatDate.Text != "")
                    {
                        string[] Lst = txtDeliveryVatDate.Text.Split(new char[] { '/' });
                        LstDate = Lst[1].ToString() + "/" + Lst[0].ToString() + "/" + Lst[2].ToString();
                    }

                    if (txtDeliveryInterStateDate.Text != "")
                    {
                        string[] CST = txtDeliveryInterStateDate.Text.Split(new char[] { '/' });
                        CSTDate = CST[1].ToString() + "/" + CST[0].ToString() + "/" + CST[2].ToString();
                    }
                    if (txtDeliveryCENVATDate.Text != "")
                    {
                        string[] Cep = txtDeliveryCENVATDate.Text.Split(new char[] { '/' });
                        CepDate = Cep[1].ToString() + "/" + Cep[0].ToString() + "/" + Cep[2].ToString();
                    }

                        SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TITLE",DDLDileveryName.SelectedItem.Text.Trim()),
                                            new SqlParameter("@CONTACTNAME",txtDileveryName.Text.Trim()),
                                            new SqlParameter("@ADD1",txtDileveryAddress1.Text.Trim()),
                                            new SqlParameter("@ADD2",txtDileveryAddress2.Text.Trim()),
                                            new SqlParameter("@ADD3",txtDileveryAddress3.Text.Trim()),
                                            new SqlParameter("@ADD4",txtDileveryAddress4.Text.Trim()),
                                            new SqlParameter("@PINCODE",txtDileveryPincode.Text.Trim()),
											new SqlParameter("@place", TxtDileveryPlace.Text.Trim()),
                                            new SqlParameter("@fax", TxtDileveryFax.Text.Trim()),
                                            new SqlParameter("@phone", TxtDileveryPhone.Text.Trim()),new SqlParameter("@STATEID",DDLDileveryState.SelectedValue),
                                            new SqlParameter("@COUNTRY",DDLDileveryCountry.SelectedItem.Text.Trim()),
                                            new SqlParameter("@LSTNUM",txtVat.Text.Trim()),
                                            new SqlParameter("@LSTDATE",LstDate),
                                            new SqlParameter("@CSTNUM",txtDeliveryInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate),
                                            new SqlParameter("@CEPANUM",txtDeliveryCENVAT.Text.Trim()),
                                            new SqlParameter("@CEPADATE",CepDate),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                        };
                        DU.executeprocedure("usp_update_ACC_LedgerDeliveryAddressDetails", sparam);

                    
                }
                else
                {

                    string LstDate = "";
                    string CSTDate = "";
                    string CepDate = "";



                    if (txtDeliveryVatDate.Text != "")
                    {
                        string[] Lst = txtDeliveryVatDate.Text.Split(new char[] { '/' });
                        LstDate = Lst[1].ToString() + "/" + Lst[0].ToString() + "/" + Lst[2].ToString();
                    }

                    if (txtDeliveryInterStateDate.Text != "")
                    {
                        string[] CST = txtDeliveryInterStateDate.Text.Split(new char[] { '/' });
                        CSTDate = CST[1].ToString() + "/" + CST[0].ToString() + "/" + CST[2].ToString();
                    }
                    if (txtDeliveryCENVATDate.Text != "")
                    {
                        string[] Cep = txtDeliveryCENVATDate.Text.Split(new char[] { '/' });
                        CepDate = Cep[1].ToString() + "/" + Cep[0].ToString() + "/" + Cep[2].ToString();
                    }

                    SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TITLE",DDLDileveryName.SelectedItem.Text.Trim()),
                                            new SqlParameter("@CONTACTNAME",txtDileveryName.Text.Trim()),
                                            new SqlParameter("@ADD1",txtDileveryAddress1.Text.Trim()),
                                            new SqlParameter("@ADD2",txtDileveryAddress2.Text.Trim()),
                                            new SqlParameter("@ADD3",txtDileveryAddress3.Text.Trim()),
                                            new SqlParameter("@ADD4",txtDileveryAddress4.Text.Trim()),
                                            new SqlParameter("@PINCODE",txtDileveryPincode.Text.Trim()),
                                            new SqlParameter("@STATEID",DDLDileveryState.SelectedValue),
                                            new SqlParameter("@COUNTRY",DDLDileveryCountry.SelectedItem.Text.Trim()),
											new SqlParameter("@place", TxtDileveryPlace.Text.Trim()),
                                            new SqlParameter("@fax", TxtDileveryFax.Text.Trim()),
                                            new SqlParameter("@phone", TxtDileveryPhone.Text.Trim()),
                                            new SqlParameter("@LSTNUM",txtVat.Text.Trim()),
                                            new SqlParameter("@LSTDATE",LstDate),
                                            new SqlParameter("@CSTNUM",txtDeliveryInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate),
                                            new SqlParameter("@CEPANUM",txtDeliveryCENVAT.Text.Trim()),
                                            new SqlParameter("@CEPADATE",CepDate),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };
                    DU.executeprocedure("USP_ACC_SaveLedgerDeliveryAddressDetails", sparam);
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
                lblMsg.Attributes.Remove("class");
                lblMsg.Attributes.Add("class", "false");
            }
        }

        protected void UpdateRegistrationDetails()
        {
            try
            {
                string sql1 = "select * from ACC_LEDREGDETAILS where lid=" + LID;
                DataTable DT = DU.getdata(sql1);
                if (DT.Rows.Count > 0)
                {

                    string PANDate = "";
                    string VatDate = "";
                    string CSTDate = "";
                    string TDSDate = "";
                    string STDate = "";
                    string LTDate = "";
                    string CENVATDate = "";
                    if (txtRegPANDate.Text != "")
                    {
                        string[] Pan = txtRegPANDate.Text.Split(new char[] { '/' });
                        PANDate = Pan[1].ToString() + "/" + Pan[0].ToString() + "/" + Pan[2].ToString();
                    }
                    if (txtRegVATDate.Text != "")
                    {
                        string[] DedcutionTax = txtRegVATDate.Text.Split(new char[] { '/' });
                        VatDate = DedcutionTax [1].ToString() + "/" + DedcutionTax [0].ToString() + "/" + DedcutionTax [2].ToString();
                    }
                    if (txtRegInterStateDate.Text != "")
                    {
                        string[] RegInterState = txtRegInterStateDate.Text.Split(new char[] { '/' });
                        CSTDate  = RegInterState[1].ToString() + "/" + RegInterState[0].ToString() + "/" + RegInterState[2].ToString();
                    }
                    if (txtRegTaxDeductionDate.Text != "")
                    {
                        string[] RegTaxDeduction = txtRegTaxDeductionDate.Text.Split(new char[] { '/' });
                        TDSDate = RegTaxDeduction[1].ToString() + "/" + RegTaxDeduction[0].ToString() + "/" + RegTaxDeduction[2].ToString();
                    }
                    if (txtRegServiceTaxDate.Text != "")
                    {
                        string[] RegService = txtRegServiceTaxDate.Text.Split(new char[] { '/' });
                        STDate = RegService[1].ToString() + "/" + RegService[0].ToString() + "/" + RegService[2].ToString();
                    }
                    if (txtRegLuxuryDate.Text != "")
                    {
                        string[] RegLuxury = txtRegLuxuryDate.Text.Split(new char[] { '/' });
                        LTDate = RegLuxury[1].ToString() + "/" + RegLuxury[0].ToString() + "/" + RegLuxury[2].ToString();
                    }
                    if (txtRegCVNNETDate.Text != "")
                    {
                        string[] RegCVNNET = txtRegCVNNETDate.Text.Split(new char[] { '/' });
                        CENVATDate = RegCVNNET[1].ToString() + "/" + RegCVNNET[0].ToString() + "/" + RegCVNNET[2].ToString();
                    }
                    

                    SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@PAN",txtRegPAN.Text.Trim()),
                                            new SqlParameter("@PANDATE",PANDate),
                                            new SqlParameter("@VATTIN",txtRegVAT.Text.Trim()),
                                            new SqlParameter("@VATTINDATE",VatDate.ToString()),
                                            new SqlParameter("@CSTNO",txtRegInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate.ToString()),
                                            new SqlParameter("@TDSNO",txtRegTaxDeduction.Text.Trim()),
                                            new SqlParameter("@TDSDATE",TDSDate.ToString()),
                                            new SqlParameter("@SERTNO",txtRegServicetax.Text.Trim()),
                                            new SqlParameter("@SERTNDATE",STDate.ToString()),
                                            new SqlParameter("@LTNO",txtRegLuxury.Text.Trim()),
                                            new SqlParameter("@LTNDATE",LTDate.ToString()),
                                            new SqlParameter("@CEPAN",txtRegCVNNET.Text.Trim()),
                                            new SqlParameter("@CEPANDATE",CENVATDate.ToString()),
                                            new SqlParameter("@PANREF",txtRegPanRef.Text.Trim()),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                        };
                    DU.executeprocedure("USP_Update_ACC_SaveRegistrationDetails", sparam);

                }
                else
                {
                    lblMsg.Text = "insert";
                    string PANDate = "";
                    string VatDate = "";
                    string CSTDate = "";
                    string TDSDate = "";
                    string STDate = "";
                    string LTDate = "";
                    string CENVATDate = "";
                    if (txtRegPANDate.Text != "")
                    {
                        string[] Pan = txtRegPANDate.Text.Split(new char[] { '/' });
                        PANDate = Pan[1].ToString() + "/" + Pan[0].ToString() + "/" + Pan[2].ToString();
                    }
                    if (txtRegVATDate.Text != "")
                    {
                        string[] DedcutionTax = txtRegVATDate.Text.Split(new char[] { '/' });
                        VatDate = DedcutionTax[1].ToString() + "/" + DedcutionTax[0].ToString() + "/" + DedcutionTax[2].ToString();
                    }
                    if (txtRegInterStateDate.Text != "")
                    {
                        string[] RegInterState = txtRegInterStateDate.Text.Split(new char[] { '/' });
                        CSTDate = RegInterState[1].ToString() + "/" + RegInterState[0].ToString() + "/" + RegInterState[2].ToString();
                    }
                    if (txtRegTaxDeductionDate.Text != "")
                    {
                        string[] RegTaxDeduction = txtRegTaxDeductionDate.Text.Split(new char[] { '/' });
                        TDSDate = RegTaxDeduction[1].ToString() + "/" + RegTaxDeduction[0].ToString() + "/" + RegTaxDeduction[2].ToString();
                    }
                    if (txtRegServiceTaxDate.Text != "")
                    {
                        string[] RegService = txtRegServiceTaxDate.Text.Split(new char[] { '/' });
                        STDate = RegService[1].ToString() + "/" + RegService[0].ToString() + "/" + RegService[2].ToString();
                    }
                    if (txtRegLuxuryDate.Text != "")
                    {
                        string[] RegLuxury = txtRegLuxuryDate.Text.Split(new char[] { '/' });
                        LTDate = RegLuxury[1].ToString() + "/" + RegLuxury[0].ToString() + "/" + RegLuxury[2].ToString();
                    }
                    if (txtRegCVNNETDate.Text != "")
                    {
                        string[] RegCVNNET = txtRegCVNNETDate.Text.Split(new char[] { '/' });
                        CENVATDate = RegCVNNET[1].ToString() + "/" + RegCVNNET[0].ToString() + "/" + RegCVNNET[2].ToString();
                    }

                    SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@PAN",txtRegPAN.Text.Trim()),
                                            new SqlParameter("@PANDATE",PANDate.ToString()),
                                            new SqlParameter("@VATTIN",txtRegVAT.Text.Trim()),
                                            new SqlParameter("@VATTINDATE",VatDate.ToString()),
                                            new SqlParameter("@CSTNO",txtRegInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate.ToString()),
                                            new SqlParameter("@TDSNO",txtRegTaxDeduction.Text.Trim()),
                                            new SqlParameter("@TDSDATE",TDSDate.ToString()),
                                            new SqlParameter("@SERTNO",txtRegServicetax.Text.Trim()),
                                            new SqlParameter("@SERTNDATE",STDate.ToString()),
                                            new SqlParameter("@LTNO",txtRegLuxury.Text.Trim()),
                                            new SqlParameter("@LTNDATE",LTDate.ToString()),
                                            new SqlParameter("@CEPAN",txtRegCVNNET.Text.Trim()),
                                            new SqlParameter("@CEPANDATE",CENVATDate.ToString()),
                                            new SqlParameter("@PANREF",txtRegPanRef.Text.Trim()),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };
                    
                    DU.executeprocedure("USP_ACC_SaveRegistrationDetails", sparam);
                }
            }
            catch (Exception ex)
            {
                lblMsg.Attributes.Remove("class");
                lblMsg.Attributes.Add("class", "false");
                lblMsg.Text = ex.Message;
            }
        }

        protected void UpdateOthersDetails()
    {
          try
            {
                string sql1 = "select * from  ACC_LEDOTHERDETAILS where lid=" + LID;
                DataTable DT = DU.getdata(sql1);
                if (DT.Rows.Count > 0)
                {
                    //lblMsg.Text="updateotherdetails";

                    SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@ACTIVE",CHKAvtive.Checked),
                                            new SqlParameter("@TCS",chkApplyTCS.Checked),
                                            new SqlParameter("@CREDITPERIOD",txtCreditPeriod.Text.Trim()),
                                            new SqlParameter("@CREDITLIMIT",txtCreditLimit.Text.Trim()),
                                            new SqlParameter("@PURTAXMAINCLASSID",ddlPurchase.SelectedValue),
                                            new SqlParameter("@SALETAXMAINCLASSID",ddlSales.SelectedValue),
                                            new SqlParameter("@SPRID",ddlSalePerson.SelectedValue),
                                            new SqlParameter("@SPGID",ddlPriceGroup.SelectedValue),
                                            new SqlParameter("@SUBTAXID","0"),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                        };
                    DU.executeprocedure("USP_Update_ACC_SaveLedgerOtherDetails", sparam);
                    
            }
              else
                {
                   
                    SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@ACTIVE",CHKAvtive.Checked),
                                            new SqlParameter("@TCS",chkApplyTCS.Checked),
                                            new SqlParameter("@CREDITPERIOD",txtCreditPeriod.Text.Trim()),
                                            new SqlParameter("@CREDITLIMIT",txtCreditLimit.Text.Trim()),
                                            new SqlParameter("@PURTAXMAINCLASSID",ddlPurchase.SelectedValue),
                                            new SqlParameter("@SALETAXMAINCLASSID",ddlSales.SelectedValue),
                                            new SqlParameter("@SPRID",ddlSalePerson.SelectedValue),
                                            new SqlParameter("@SPGID",ddlPriceGroup.SelectedValue),
                                            new SqlParameter("@SUBTAXID","0"),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };
                    DU.executeprocedure("USP_ACC_SaveLedgerOtherDetails", sparam);
                }
          }
          catch (Exception ex)
          {
              lblMsg.Attributes.Remove("class");
              lblMsg.Attributes.Add("class", "false");
              lblMsg.Text = ex.Message;
          }
    }

        protected void UpdateTermConditions()
      {

           try
            {
                string sql1 = "select TRMID from  ACC_LEDTERMSCONDITIONS where lid=" + LID;
                DataTable DT = DU.getdata(sql1);
                if (DT.Rows.Count > 0)
                {
             
                  SqlParameter[] sparam =
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TRMID",lstTermCondition.SelectedValue),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                        };
                  DU.executeprocedure("usp_Update_ACC_LEDTERMSCONDITIONS", sparam);
                }
                  else
                {
                   SqlParameter[] sparam =
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TRMID",lstTermCondition.SelectedValue),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };
                     DU.executeprocedure("usp_insert_ACC_LEDTERMSCONDITIONS", sparam);
                }
           }
              catch (Exception ex)
              {
                  lblMsg.Attributes.Remove("class");
                  lblMsg.Attributes.Add("class", "false");
                  lblMsg.Text = ex.Message;
              }
          }
      
        protected void DDLTaxType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Convert.ToInt32(DDLTaxType.SelectedValue) > 0)
            {
                DDLMainClass.Enabled = true;
                BindTaxMainClass();
                BindTaxSubClass();

            }
            else
            {
                DDLMainClass.Items.Clear();
                DDLMainClass.Items.Insert(0, new ListItem("", "0"));
                DDLMainClass.Enabled = false;
                DDLSubClass.Items.Clear();
                DDLSubClass.Items.Insert(0, new ListItem("", "0"));
                DDLSubClass.Enabled = false;
                

            }
        }
        protected void DDLMainClass_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (Convert.ToInt32(DDLMainClass.SelectedValue) > 0)
            {
                DDLSubClass.Enabled = true;
                BindTaxSubClass();

            }
            else
            {
                DDLSubClass.Items.Clear();
                DDLSubClass.Items.Insert(0, new ListItem("", "0"));
                DDLSubClass.Enabled = false;
            }
        }
 }